home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Original Shareware 1.1
/
The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso
/
19
/
madtrb40.zip
/
IXTON.INC
< prev
next >
Wrap
Text File
|
1986-01-21
|
2KB
|
47 lines
Function IXtoN(x : integer; n : integer) : integer;
{ This include file contains the x_to_n function that computes }
{ the Nth power of an integer number, where N is an integer. }
{ Author : Herb Holden }
{ Date : 11/17/84 }
{ Application : All systems. }
{ }
{ This function was taken from TUG newsletter vol I, issue 5 }
{ pg. 32. }
{ Modified to be a pure integer function by Claire A. Rinehart }
Var
p : integer;
y : real;
Begin {computes x to the nth power}
if x = 0 then
begin
if n = 0 then
begin {0 to the 0 is undefined}
writeln('** error in IxTOn: x=0, n=0 **');
y := 1/0
end
else
IxTOn := 0 {0 to the n is 0}
end
else
begin
if n < 0 then {x to -n is (1/x) to n and can not be assigned to an integer variable}
begin
writeln('ERROR!! Attempted to assign a fraction to an integer.');
y := 1/0;
end;
if odd(n) then {prepare for while loop}
p := x
else
p := 1; {x to 0 will be 1}
n := n shr 1;
while n <> 0 do
begin
x := sqr(x);
if odd(n) then p := p * x;
n := n shr 1
end;
IxTOn := p
end
end; {IxTOn}